#!/bin/bash

# ----------------------------------------------------------------------
# Filename:   UserIdentity.sh
# Version:    1.0
# Date:       2013/12/10
# Author:     huijing.hei
# Email:      huijing.hei@cs2c.com.cn
# Summary:    03系统安全功能-07身份鉴别-02验证用户标识的唯一性
# Notes:       ***
# Copyright:    China Standard Software Co., Ltd.
# History：     
#             Version 1.0, 2013/12/10
#             - user identity is uniq.
# ----------------------------------------------------------------------

##! @TODO: add user
##! @AUTHOR: huijing.hei
##! @VERSION: 1.0 
##! @OUT: 0 => success; 1 => failure

function DoSetup()
{
    trap DoCleanup EXIT INT 

    IsRoot
    EchoResult "root"


    TEST_USER=test1234
    TEST_USER_PASSWORD=useriden123
    TEST_USER1=test333

    UserCheck "${TEST_USER}" && userdel -r "${TEST_USER}"
    UserCheck "${TEST_USER1}" && userdel -r "${TEST_USER1}"

    AddUserPasswd "${TEST_USER}" "${TEST_USER_PASSWORD}"
    EchoResult "add user ${TEST_USER}"

}

##! @TODO: test, check user id
##! @AUTHOR: huijing.hei
##! @VERSION: 1.0 
##! @OUT: 0 => success; 1 => failure
function DoTest()
{
    su - ${TEST_USER} -c "id; exit"
    EchoResult "${TEST_USER} exec commands"

    local USERID=`id -ru ${TEST_USER}`
    ! adduser -u ${USERID} ${TEST_USER1}
    EchoResult "adduser -u ${USERID} ${TEST_USER1} failed"
}
##! @TODO: cleanup, delete user
##! @AUTHOR: huijing.hei
##! @VERSION: 1.0 
##! @OUT: 0 => success; 1 => failure

function DoCleanup()
{
    UserCheck "${TEST_USER}" && userdel -r "${TEST_USER}"
    UserCheck "${TEST_USER1}" && userdel -r "${TEST_USER1}"
}

# include lib files

if [ -z "$SFROOT" ]
then
    echo "SFROOT is null, pls check"
    exit 1
fi

. ${SFROOT}/lib/Echo.sh
. ${SFROOT}/lib/Check.sh
. ${SFROOT}/testcases/Security/lib/UserOps.sh

export LANG=C

DoSetup
DoTest
EchoResult "testcase: user identity is uniq"
echo ""
